//
//  RKHomeController.swift
//  RKWeibo
//
//  Created by Rick on 2017/3/2.
//  Copyright © 2017年 Ricky. All rights reserved.
//

import UIKit

class RKHomeController: RKBaseController {

    fileprivate lazy var dataSource = [String]()
    
    override func loadData() {
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.init(uptimeNanoseconds: 2)) {
            
            for i in 0..<10 {
                self.dataSource.insert(i.description, at: 0)
            }
            self.refreshControl?.endRefreshing()
            self.tableView?.reloadData()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @objc fileprivate func leftBarBtnClick()->(){
        let controller = RKTestController()
        navigationController?.pushViewController(controller, animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension RKHomeController{
    override func setupUI() {
        super.setupUI()
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(leftBarBtnClick))
//        let btn:UIButton = UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
//        btn.addTarget(self, action: #selector(leftBarBtnClick), for: .touchUpInside)
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(leftBarBtnClick))
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: NSStringFromClass(UITableViewCell.self))
    }
}

//MARK: - UITableView 数据源方法
extension RKHomeController{
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView .dequeueReusableCell(withIdentifier: NSStringFromClass(UITableViewCell.self), for: indexPath)
        cell.textLabel?.text = dataSource[indexPath.row]
        return cell
    }
}
